<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script></head>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>
<body>


<!--     <header class=" fixed" style="padding-top:0.4rem;">
        <div class="head">
          <div class="head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
          <h3>推荐商品</h3>
          <div class="head-r"></div>
      </div>
  </header>

  <div class="head-d" style="padding-top:0.4rem;"></div> -->

  <header class="head" style="padding-top:0.4rem;" id="head" >
    <div class="head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
    <h3 id="title">推荐商品</h3>
    <div class="head-r"></div>
</header>
<div class="head-d" style="padding-top:0.4rem;"></div>


<div id="list"></div>
<script type="text/template" id="template">
    <ul class="classify">
        {{~it.data:value:index}}
        <li onclick="check_detail({{=value.id}})">
            {{? value.image != ''}}
            <img src="{{=value.image}}" alt=""> {{??}}
            <img src="image/classify.jpg" alt=""> {{?}}
            <dl>
                <dt>{{=value.title}}</dt>
                <dd>￥{{=value.coin}}金币</dd>
                <!-- <del>￥{{=value.price}}</del> -->
            </dl>
        </li>
        {{~}}
    </ul>
</script>


</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/javascript">
    apiready = function() {
        getData(0);
        pullLoading();
        title = api.pageParam.title;

        $('#title').text(title);


    }

    function getData(more) {
        var id = api.pageParam.id;
        if (more) {
            page += 1;
        } else {
            page = 1;
        }

        api.ajax({
            url: webAddress + '/api/home/product-coin',
            method: 'get',
            data: {
                values: {
                    page: page,
                    // category_id: id,
                    // keyword:keyword,
                    row: 10
                },

            }
        }, function(ret, err) {
            if (ret) {
                // alert(JSON.stringify(ret));
                if (ret.data !='') {
                    templateFun(ret, 1);
                } else {
                    templateFun(ret);
                }

            } else {
                // alert(JSON.stringify(err));
            }
        });
    }

    function templateFun(ret, more) {

        if (more) {
            var template = $api.byId('template');
            var dotFn = doT.template(template.innerHTML);
            var html = dotFn(ret);
            var list = $api.byId('list');
            $api.append(list, html);
        } else {
            // api.toast({
            //     msg: '没有更多了',
            //     duration: 2000,
            //     location: 'bottom'
            // });
            // return;
        }
    }


    function check_detail(id) {
      var token = $api.getStorage('token');
      if(!token){
        api.openWin({
            name: 'login',
            url: './login.html',
            pageParam: {
                name: 'test'
            }
        });
        return;
    }

      if (title=='当月商品') {
        api.openWin({
            name: 'month_goods_details',
            url: './month_goods_details.html',
            pageParam: {
                id: id
            }
        });
      }
        // api.openWin({
        //     name: 'goods_details',
        //     url: './goods_details.html',
        //     pageParam: {
        //         id: id
        //     }
        // });
    }

    function pullLoading() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err) {

            getData(1);
            // loadData(1,type);
        });
    }






    function closeWin() {
        api.closeWin({});
    }
</script>
</html>
